package com.jy.datapipeline.export.service.impl;

import com.jy.datapipeline.export.dao.ExpTaskExecuteDetailLogDao;
import com.jy.datapipeline.export.dao.repo.ExpTaskExecuteDetailLogDaoRepo;
import com.jy.datapipeline.export.entity.ExpTaskExecuteDetailLogModel;
import com.jy.datapipeline.export.service.ExpTaskExecuteDetailLogService;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@Transactional
public class ExpTaskExecuteDetailLogServiceImpl implements ExpTaskExecuteDetailLogService {
    @Autowired
    private ExpTaskExecuteDetailLogDao expTaskExecuteDetailLogDao;
    @Autowired
    private ExpTaskExecuteDetailLogDaoRepo expTaskExecuteDetailLogDaoRepo;
    @Override
    public List<Map<String, Object>> findExpTaskExecuteDetailByList(String taskId,
        String taskExecuteLogId, String ruleTbl, String expStatus, int iDisplayStart,
        int iDisplayLength) {
        return this.expTaskExecuteDetailLogDao.findExpTaskExecuteDetailByList(taskId, taskExecuteLogId,ruleTbl,
            expStatus,iDisplayStart,iDisplayLength);
    }

    @Override
    public int findExpTaskExecuteDetailByCount(String taskId, String taskExecuteLogId,
        String ruleTbl, String expStatus) {

        return this.expTaskExecuteDetailLogDao.findExpTaskExecuteDetailByCount(taskId,taskExecuteLogId,ruleTbl,expStatus);
    }

     @Override
     public boolean deleteByTaskId(String taskId) {
            return this.expTaskExecuteDetailLogDao.deleteByTaskId(taskId);
     }

    @Override
    public boolean deleteByTaskExecuteLogId(String taskExecuteLogId) {
        return this.expTaskExecuteDetailLogDao.deleteByTaskExecuteLogId(taskExecuteLogId);
    }

    @Override
    public boolean updateExpStatus(ExpTaskExecuteDetailLogModel etedl) {
        return this.expTaskExecuteDetailLogDao.updateExpStatus(etedl);
    }

    @Override
    public List<ExpTaskExecuteDetailLogModel> findByExpStatus(int expStatus, int dealyhour) {
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR,dealyhour);
        //log.info("findByExpStatus dealy hour {} ,currentDate:{}",dealyhour, DateUtils.formatDate(calendar.getTime(),"yyyy-MM-dd HH:mm:ss"));
        return this.expTaskExecuteDetailLogDaoRepo.findByUpdateTimeAfterAndExpStatus(calendar.getTime(),expStatus);
    }

    @Override
    public List<ExpTaskExecuteDetailLogModel> findBytaskExecutelogLogIdAndExpStatusLessThan(
        String taskExecutelogLogId, int expStatus) {
        return this.expTaskExecuteDetailLogDaoRepo.findBytaskExecutelogLogIdAndExpStatusLessThan(taskExecutelogLogId,expStatus);
    }

    @Override
    public List<ExpTaskExecuteDetailLogModel> findBytaskExecutelogLogIdAndExpStatus(
        String taskExecutelogLogId, int expStatus) {
        return this.expTaskExecuteDetailLogDaoRepo.findBytaskExecutelogLogIdAndExpStatus(taskExecutelogLogId,expStatus);
    }

    @Override
    public List<ExpTaskExecuteDetailLogModel> findBytaskExecutelogLogId(
        String taskExecutelogLogId) {
        return this.expTaskExecuteDetailLogDaoRepo.findBytaskExecutelogLogId(taskExecutelogLogId);
    }

    @Override
    public List<Map<String, Object>> findBytaskExecutelogLogIds(String taskExecutelogLogId) {
        return this.expTaskExecuteDetailLogDao.findBytaskExecutelogLogId(taskExecutelogLogId);
    }

    @Override
    public String queryLatestStatusByTaskId(String task_id) {
        return expTaskExecuteDetailLogDao.findExpTaskExeDetailLatestExpStatusByTaskId(task_id);
    }
}
